# -*- coding: utf-8 -*-
# @author xh
# @date 2021/4/1 5:20 下午

baseHTML = """ 
            <html>
            <head>
            <link rel="icon" 
                href="https://yy-s.zuoyebang.cc/static/mcommon/css/resource/favicon.ico" type="image/x-icon">
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <script type="text/x-mathjax-config">
                MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}});
            </script>
            <script type="text/javascript"
                src="https://yy-s.zuoyebang.cc/static/mathjax_274/MathJax.js?config=svgsnippet-update190725">
            </script>
            </head>
            <body>
            <div style="font-size:18px;padding:5px">
            %s
            </div>
            </body>
            <script>MathJax.Hub.Queue(["Typeset", MathJax.Hub]);</script>
            </html>"""


def make_html(diff_list, hfilename, split=False):
    # diff_list = []

    i = 0
    n_o = 1
    file_head = hfilename.split('.')[0]

    message = ""
    # for index in range(len(diff_list)):
    # for dIt in diff_list:
    body = ""
    i += 1
    # score1, query_url1, query1, table_name_id1, ques1 = j
    question, answer = diff_list

    body += """
    %s
    ----------------------------------------
    %s
    """ % (question, answer)

    message += """
            %s
            """ % body

    if split and i != 0 and i % 100 == 0:
        homework = baseHTML % message
        message = ''
        result = open(file_head + str(n_o) + '.html', 'w')
        result.write(homework)
        n_o += 1

    if message:
        homework = baseHTML % message
        result = open(file_head + (str(n_o) if split else '') + '.html', 'w')
        result.write(homework)


if __name__ == '__main__':
    make_html(['问题', '答案'], 'test.html')
